﻿using System.Threading.Tasks;
using Abp.Dependency;
using Castle.Core.Logging;

namespace Vecen.BangChuang.Net.Sms {
    /// <summary>
    /// Null SmsSender
    /// </summary>
    public class NullSmsSender: SmsSenderBase,ITransientDependency {
        /// <summary>
        /// Null instance
        /// </summary>
        public static NullSmsSender Null;

        /// <summary>
        /// Logger
        /// </summary>
        public ILogger Logger { get; set; }

        /// <summary>
        /// Creates a new <see cref="NullSmsSender"/> object.
        /// </summary>
        /// <param name="configuration">Configuration</param>
        public NullSmsSender(ISmsSenderConfiguration configuration): base(configuration) {
            Logger = NullLogger.Instance;
        }

        /// <summary>
        /// Send Sms
        /// </summary>
        /// <param name="sms"></param>
        protected override void SendSms(SmsMessageDto sms) {
            Logger.Warn("USING NullSmsSender!");
            Logger.Debug("SendSms:");
            LogSms(sms);
        }

        /// <summary>
        /// Send Sms
        /// </summary>
        /// <param name="sms"></param>
        /// <returns></returns>
        protected override Task SendSmsAsync(SmsMessageDto sms) {
            Logger.Warn("USING NullSmsSender!");
            Logger.Debug("SendSmsAsync:");
            LogSms(sms);
            return Task.FromResult(0);
        }

        private void LogSms(SmsMessageDto sms) {
            Logger.Debug(sms.ReceiverPhone);
            Logger.Debug(sms.TemplateCode);
            Logger.Debug(string.Join("|", sms.TemplateParams));
            Logger.Debug(sms.FreeSignName);
        }
    }
}